package com.sxbbc.common.basics.service.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import com.sxbbc.common.basics.utils.dto.Properties;

/**
 * 初始化加载
 * @author arno
 *
 */
@Component
public class Config implements ApplicationListener<ContextRefreshedEvent> {
	
	@Value("#{thirdsetting['email_accesskey']}")
	public  String accesskey ;
	@Value("#{thirdsetting['email_secretkey']}")
	public  String secretkey ;
	@Value("#{thirdsetting['fromAlias']}")
	public  String fromAlias ;
	@Value("#{thirdsetting['signId']}")
	public  String signId;
	@Value("#{thirdsetting['templateId']}")
	public  String templateId;
	
	
	@Value("#{thirdsetting['sms_appkey']}")
	private String appkey;
	@Value("#{thirdsetting['sms_validmodelcode']}")
	private String modelcode;
	
	/**
	 * 
	 */
	@Value("#{thirdsetting['qiniu_ak']}")
	private String ak;
	@Value("#{thirdsetting['qiniu_sk']}")
	private String sk;
	@Value("#{thirdsetting['bucket']}")
	private String bucket;
	@Value("#{thirdsetting['domain']}")
	private String domain;
	
	/**
	 * RSA
	 */
	@Value("#{thirdsetting['rsa_file_path']}")
	private String rsa_file_path;
	
	
	@Value("#{thirdsetting['api_domain']}")
	private String api_domain;
	@Value("#{thirdsetting['wap_domain']}")
	private String wap_domain;
	@Value("#{thirdsetting['pc_domain']}")
	private String pc_domain;
	@Value("#{thirdsetting['admin_domain']}")
	private String admin_domain;
	@Value("#{thirdsetting['business_domain']}")
	private String businessDomain;
	@Value("#{thirdsetting['sms_aliyun_accessKeyId']}")
	private String aliAccessKeyId;
	@Value("#{thirdsetting['sms_aliyun_accessKeySecret']}")
	private String aliAccessKeySecret;
	@Value("#{thirdsetting['sms_aliyun_sign']}")
	private String aliSign;
	@Value("#{thirdsetting['sms_aliyun_templateCode']}")
	private String aliTemplateCode;

	@Value("#{thirdsetting['ry_key']}")
	private String ryKey;
	@Value("#{thirdsetting['ry_secret']}")
	private String rySecret;
	@Value("#{thirdsetting['jpush_key']}")
	private String jpushKey;
	@Value("#{thirdsetting['jpush_secret']}")
	private String jpushSecret;
	
	@Value("#{thirdsetting['jh_opend_id']}")
	private String jhOpendId;
	@Value("#{thirdsetting['jh_bank_key']}")
	private String jhBankKey;
	@Value("#{thirdsetting['jh_phone_detail_key']}")
	private String jhPhoneDetailKey;
	@Value("#{thirdsetting['jh_recharge_phone_key']}")
	private String jhRechargePhoneKey;
	@Value("#{thirdsetting['jh_recharge_refueling_key']}")
	private String jhRechargeRefuelingKey;

	@Value("#{thirdsetting['map_key']}")
	private String mapKey;
	@Value("#{thirdsetting['amap_key']}")
	private String amapKey;
	
	/** 阿里云物流接口appCode*/
	@Value("#{thirdsetting['ali_exp_appcode']}")
	private String aliExpAppCode;
	/** 阿里云物流接口appKey*/
	@Value("#{thirdsetting['ali_exp_appkey']}")
	private String aliExpAppKey;
	/** 阿里云物流接口appSecret*/
	@Value("#{thirdsetting['ali_exp_appsecret']}")
	private String aliExpAppSecret;
	
	public static Properties properties;
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		
		if(event.getApplicationContext().getParent() == null){
			//加载第三方配置
			properties=new Properties();
			properties.setAccesskey(accesskey);
			properties.setSecretkey(secretkey);
			properties.setFromAlias(fromAlias);
			properties.setSmsAppkey(appkey);
			properties.setSmsValidmodelcode(modelcode);
			properties.setQiniuAk(ak);
			properties.setQiniuSk(sk);
			properties.setBucket(bucket);
			properties.setDomain(domain);
			properties.setRsaFilepath(rsa_file_path);
			properties.setSignId(signId);
			properties.setTemplateId(templateId);
			properties.setApiDomain(api_domain);
			properties.setWapDomain(wap_domain);
			properties.setPcDomain(pc_domain);
			properties.setAdminDomain(admin_domain);
			properties.setAliAccessKeyId(aliAccessKeyId);
			properties.setAliAccessKeySecret(aliAccessKeySecret);
			properties.setAliSign(aliSign);
			properties.setAliTemplateCode(aliTemplateCode);
			properties.setRyKey(ryKey);
			properties.setRySecret(rySecret);
			properties.setJpushKey(jpushKey);
			properties.setJpushSecret(jpushSecret);
			properties.setJhBankKey(jhBankKey);
			properties.setJhOpendId(jhOpendId);
			properties.setJhPhoneDetailKey(jhPhoneDetailKey);
			properties.setJhRechargePhoneKey(jhRechargePhoneKey);
			properties.setJhRechargeRefuelingKey(jhRechargeRefuelingKey);
			properties.setMapKey(mapKey);
			properties.setAmapKey(amapKey);
			properties.setAliExpAppCode(aliExpAppCode);
			properties.setAliExpAppKey(aliExpAppKey);
			properties.setAliExpAppSecret(aliExpAppSecret);
			properties.setBusinessDomain(businessDomain);
			System.out.println("通用公共层加载配置成功。。。");
		}
	}
}
